<template>
	<view class="container">
		<view class="input-box">
			<input @input="inputChange" v-model="name" placeholder="输入院校标签" placeholder-class="placeholder-class" />
		</view>
		<view class="input-label">{{tip}}</view>
		<view class="show-name-box">
			<view @tap="doSubmit" class="show-name" v-show="isShow">{{showName}}</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				t: 0,
				name: '',
				tip: '自定义院校标签最多8个字',
				timer: null,
				showName: '',
				isShow: false
			}
		},
		
		onLoad(options) {
			if (options.t) {
				this.t = options.t
			}
		},
		
		methods: {
			
			inputChange() {
				const that = this
				if (that.timer) {
					clearTimeout(that.timer)
				}
				that.timer = setTimeout(function() {
					if (that.name.length > 0) {
						that.isShow = true
						that.tip = '点击添加标签'
						that.showName = that.name
					} else {
						that.isShow = false
					}
				}, 1000)
			},
			
			doSubmit() {
				const that = this
				let customLabelList = uni.getStorageSync('customLabelList')
				if (!customLabelList) {
					customLabelList = []
				}
				customLabelList.push({name: that.name, isSelected: true})
				uni.setStorageSync('customLabelList', customLabelList)
				uni.redirectTo({
					url: '/pages/select_label/select_label?t=' + that.t
				})
			}
			
		}
	}
</script>

<style>
	.container {
		width: 750rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
	
	.input-box {
		width: 650rpx;
		margin-top: 50rpx;
		border-bottom: 2rpx solid #e5e5e5;
		padding-bottom: 20rpx;
	}
	
	.input-box input {
		height: 100rpx;
		font-size: 72rpx;
	}
	
	.placeholder-class {
		color: #e3e3e3;
		font-size: 72rpx;
	}
	
	.input-label {
		width: 650rpx;
		color: #999999;
		margin-top: 24rpx;
	}
	
	.show-name-box {
		width: 650rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
	}
	
	.show-name {
		padding-left: 20rpx;
		padding-right: 20rpx;
		padding-top: 10rpx;
		padding-bottom: 10rpx;
		border: 2rpx solid #e5e5e5;
		border-radius: 10rpx;
		margin-top: 10rpx;
		font-size: 36rpx;
		color: #45d6b7;
	}
</style>
